//
//  AddWorkController.m
//  Ten
//
//  Created by anfuer on 2018/10/31.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "AddWorkController.h"
#import "HooDatePicker.h"
@interface AddWorkController ()<HooDatePickerDelegate>
@property (weak, nonatomic) IBOutlet UIButton *btn1o;
@property (weak, nonatomic) IBOutlet UIButton *btn2o;
@property (weak, nonatomic) IBOutlet UITextField *tsf1;
@property (weak, nonatomic) IBOutlet UITextField *tsf2;
@property (weak, nonatomic) IBOutlet UITextView *tsview;
@property (nonatomic, strong) HooDatePicker *datePicker;
@end

@implementation AddWorkController
- (IBAction)back:(UIButton *)sender {

    UIViewController *viewCtl = self.navigationController.viewControllers[1];
    [self.navigationController popToViewController:viewCtl animated:YES];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.datePicker = [[HooDatePicker alloc] initWithSuperView:self.view];
    self.datePicker.delegate = self;
    self.datePicker.datePickerMode = HooDatePickerModeDate;
    NSDateFormatter *dateFormatter = [NSDate shareDateFormatter];
    [dateFormatter setDateFormat:kDateFormatYYYYMMDD];
    NSDate *maxDate = [NSDate date];
    NSDate *minDate = [dateFormatter dateFromString:@"1960-01-01"];
    [self.datePicker setDate:[NSDate date] animated:YES];
    self.datePicker.minimumDate = minDate;
    self.datePicker.maximumDate = maxDate;

}

- (IBAction)SaveBtna:(UIButton *)sender {
    
    if ([FuncPublic TextFieldisError:_tsf1]||[FuncPublic TextFieldisError:_tsf2]) {
        
        if ([[_btn1o currentTitle]containsString:@"请选择"]||[[_btn2o currentTitle]containsString:@"请选择"]) {
             [WSProgressHUD showImage:nil status:@"请完善相关数据,再提交"];
             return;
        }
//        resume_id（简历id）
//        id（可选，工作经历 的id，不传为新增，传则为编辑）
        NSMutableDictionary*mdic=[NSMutableDictionary dictionary];
        [mdic setObject:_tsf1.text forKey:@"company_name"];
        [mdic setObject:_tsf2.text forKey:@"position"];
        [mdic setObject:_tsview.text forKey:@"job_description"];
        [mdic setObject:[_btn1o currentTitle] forKey:@"entry_time"];
        [mdic setObject:[_btn2o currentTitle] forKey:@"quit_time"];
        [mdic setObject:_resume_id forKey:@"resume_id"];
        
        [FuncPublic getData:self parameters:mdic RequestUrl:edit_work_experience success:^(NSDictionary *acountInfo) {
             [WSProgressHUD showImage:nil status:acountInfo[@"msg"]];

        }];
    }
    
}
- (IBAction)ChosesBtna:(UIButton *)sender {
    [_tsf1 resignFirstResponder];
    [_tsf2 resignFirstResponder];
   
    self.datePicker.tag=sender.tag;
     [self.datePicker show];

}
- (void)datePicker:(HooDatePicker *)datePicker didSelectedDate:(NSDate*)date {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //    [dateFormatter setLocale:[NSLocale currentLocale]];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *value = [dateFormatter stringFromDate:date];
    if (datePicker.tag==1) {
        [_btn1o setTitle:value forState:UIControlStateNormal];
    }else
    {
        [_btn2o setTitle:value forState:UIControlStateNormal];
    }
}




@end
